package GUILayer;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import ControlLayer.OrderCtr;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class InvoiceMenu {
	private static InvoiceMenu instance;
	
	public JFrame frame;
	private JTextField txtInvoiceno;
	private JTextField txtPaymentdate;
	private JTextField txtPrice;

	/**e
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					InvoiceMenu window = new InvoiceMenu();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	private InvoiceMenu() {
		initialize();
	}

	public static InvoiceMenu getInstance()
	{
		if(instance==null)
		{
			instance = new InvoiceMenu();
		}
		return instance;
	}
	
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JLabel lblInvoiceNo = new JLabel("Invoice No:");
		lblInvoiceNo.setBounds(28, 25, 71, 14);
		frame.getContentPane().add(lblInvoiceNo);
		
		JLabel lblPaymentDate = new JLabel("Payment date");
		lblPaymentDate.setBounds(28, 63, 71, 14);
		frame.getContentPane().add(lblPaymentDate);
		
		JLabel lblPrice = new JLabel("Price:");
		lblPrice.setBounds(28, 100, 46, 14);
		frame.getContentPane().add(lblPrice);
		
		txtInvoiceno = new JTextField();
		txtInvoiceno.setBounds(109, 22, 86, 20);
		frame.getContentPane().add(txtInvoiceno);
		txtInvoiceno.setColumns(10);
		
		txtPaymentdate = new JTextField();
		txtPaymentdate.setBounds(109, 60, 86, 20);
		frame.getContentPane().add(txtPaymentdate);
		txtPaymentdate.setColumns(10);
		
		txtPrice = new JTextField();
		txtPrice.setText("");
		txtPrice.setBounds(109, 100, 86, 20);
		frame.getContentPane().add(txtPrice);
		txtPrice.setColumns(10);
		
		JButton btnCreate = new JButton("Create");
		btnCreate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				OrderCtr orderCtr = new OrderCtr();
				
				int invoiceNo = Integer.parseInt(txtInvoiceno.getText());
				String paymentDate = txtPaymentdate.getText();
				orderCtr.createNewInvoice(invoiceNo, paymentDate);
				txtPrice.setText(String.valueOf(orderCtr.findInvoicePrice(invoiceNo)));
			}
		});
		btnCreate.setBounds(49, 175, 89, 23);
		frame.getContentPane().add(btnCreate);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setBounds(213, 175, 89, 23);
		frame.getContentPane().add(btnCancel);
	}
}
